//
//  NearAlbumViewController.m
//  HappyTrip
//
//  Created by GeminyXC on 15-3-27.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NearAlbumViewController.h"
#import "NearbyPicObject.h"

#import "NearbyPicCollectionViewCell.h"
//照片放大页面
#import "NearbyPhotoViewController.h"

@interface NearAlbumViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>



@end

@implementation NearAlbumViewController

- (void)dealloc
{
    [_arrAlbum release];
    [super dealloc];
}

//---------------------------------
- (void)viewWillAppear:(BOOL)animated
{
//   self.tabBarController.tabBar.hidden = NO;
//////        self.navigationController.navigationBarHidden = NO;
////     self.tabBarController.tabBar.alpha = 1;
    //    //    self.tabBarController.tabBar.hidden = NO;
    //    //        self.navigationController.navigationBarHidden = NO;
    //    self.tabBarController.tabBar.alpha = 1;

//    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
//        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.tabBarController.tabBar.hidden = NO;
    
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0];
    self.tabBarController.tabBar.hidden = NO;
    self.view.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
}

//---------------------------------

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    
    self.view.backgroundColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((VIEW_WIDTH - 6) / 3, (VIEW_WIDTH - 6) / 3);
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    flowLayout.minimumInteritemSpacing = 3;
    flowLayout.minimumLineSpacing = 3;
    
    //UICollectionView继承于UIScrollView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT) collectionViewLayout:flowLayout];
    
    collectionView.dataSource = self;
    collectionView.delegate = self;
    
    collectionView.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:collectionView];
    [collectionView release];
    
    //上拉刷新,下拉加载
    //1.协议传值
    //2.将网络请求放到本页面
    //3.通知中心
    //4.block传值
    //5.在上一页面将所有数据保存到数组中,每次刷新加载本地数据
    
    //注册cell
    [collectionView registerClass:[NearbyPicCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSLog(@"%lu", self.arrAlbum.count);
    return self.arrAlbum.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NearbyPicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    NearbyPicObject *nearbyPicInfo = [self.arrAlbum objectAtIndex:indexPath.row];
    cell.nearbyPicInfo = nearbyPicInfo;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"选中当前cell:%@", indexPath);
    NearbyPhotoViewController *photoVC = [[NearbyPhotoViewController alloc] init];
    photoVC.arrPhoto = self.arrAlbum;
    photoVC.itemOK = indexPath.item;
//    photoVC.hidesBottomBarWhenPushed = YES;//可以隐藏下面的tabbar,和目前用的效果类似
    [self.navigationController pushViewController:photoVC animated:YES];
    [photoVC release];
}
- (void)leftBarButtonItemAction:(UIBarButtonItem *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
